package cn.jji8.patronSaint.quick.vision;

import org.bukkit.Location;
import org.bukkit.Particle;
import org.bukkit.entity.Player;

import java.util.Objects;

public class VisionTool {
    /**
     * 给某玩家显示矩形
     * */
    @SuppressWarnings("unused")
    public static void rectangle(Player player, Particle particle, Location location1, Location location2){
        if(location1==null|location2==null){
            return;
        }
        if(!Objects.equals(location1.getWorld(), location2.getWorld())){
            return;
        }
        rectangle(player,particle,location1.getBlockX(),location1.getBlockY(),location1.getBlockZ(),location2.getBlockX(),location2.getBlockY(),location2.getBlockZ());
    }
    /**
     * 给某玩家显示矩形
     * */
    public static void rectangle(Player player, Particle particle,int x1,int y1,int z1,int x2,int y2,int z2){
        //很久之前写的代码，改改就用，不要建议嘛。
        if(x1>x2){
            x1++;
        }else {
            x2++;
        }
        if(y1>y2){
            y1++;
        }else {
            y2++;
        }
        if(z1>z2){
            z1++;
        }else {
            z2++;
        }
        xianshix(player,particle,x1,y1,z1,x2);
        xianshiy(player,particle,x1,y1,z1,y2);
        xianshiz(player,particle,x1,y1,z1,z2);

        xianshix(player,particle,x2,y2,z2,x1);
        xianshiy(player,particle,x2,y2,z2,y1);
        xianshiz(player,particle,x2,y2,z2,z1);

        xianshix(player,particle,x2,y1,z2,x1);
        xianshiz(player,particle,x2,y1,z2,z1);

        xianshix(player,particle,x1,y2,z1,x2);
        xianshiz(player,particle,x1,y2,z1,z2);

        xianshiy(player,particle,x2,y1,z1,y2);
        xianshiy(player,particle,x1,y1,z2,y2);
    }
    //很久之前写的代码，改改就用，不要建议嘛。
    private static void xianshix(Player player,Particle particle,double x1, double y, double z, double x2){
        if(x1>x2){
            double a = x1;
            x1 = x2;
            x2 = a;
        }
        for(double i = x1;i<=x2;i++){
            player.spawnParticle(particle,i,y,z,0);
        }
    }
    //很久之前写的代码，改改就用，不要建议嘛。
    private static void xianshiy(Player player,Particle particle, double x, double y1, double z, double y2){
        if(y1>y2){
            double a = y1;
            y1 = y2;
            y2 = a;
        }
        for(double i = y1;i<=y2;i++){
            player.spawnParticle(particle,x,i,z,0);
        }
    }
    //很久之前写的代码，改改就用，不要建议嘛。
    private static void xianshiz(Player player,Particle particle, double x, double y, double z1, double z2){
        if(z1>z2){
            double a = z1;
            z1 = z2;
            z2 = a;
        }
        for(double i = z1;i<=z2;i++){
            player.spawnParticle(particle,x,y,i,0);
        }
    }
}
